package com.tange.ai.core.sample.binding

import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Color
import android.os.Build
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import com.tange.ai.core.sample.utils.Utils
import com.tange.ai.core.sample.databinding.ActivityAddTypeChooseBinding
import com.tange.base.toolkit.onClicked
import com.tange.base.ui.design.BasicDialogRequest

class BindingWaysActivity: AppCompatActivity() {

    private lateinit var binding: ActivityAddTypeChooseBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = ActivityAddTypeChooseBinding.inflate(layoutInflater).apply {
            setContentView(root)
            supportActionBar?.hide()
        }

        Utils.setStatusBar(this, Color.TRANSPARENT)

        binding.addByBluetooth.onClicked {
            startActivity(Intent(this, BindingBluetoothScanActivity::class.java))
        }

        binding.addByApScan.setOnClickListener {
            startActivity(Intent(this, BindingApScanActivity::class.java))
        }

        binding.addByDeviceScanQrCode.setOnClickListener {
            startActivity(Intent(this, BindingQrcodeActivity::class.java))
        }

        binding.addByDirectlyBind.onClicked {
            startActivity(Intent(this, BindingDirectlyActivity::class.java))
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            BasicDialogRequest(this@BindingWaysActivity).apply {
                setMessage("部份配网方式依赖\"定位权限\"，请授予")
                setPositiveText("没问题")
                setPositiveOnClicked {
                    requestPermissions(arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), 100)
                    dismiss()
                }
            }.show()
        }
    }
}